home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / lib / asm / simple_str.s < prev    next >
Encoding:
Text File  |  1998-10-04  |  4.3 KB  |  235 lines

  1. ;
  2. ; simple_string.s -- an ACE linked library module: simple string functions.
  3. ; Copyright (C) 1998 David Benn
  4. ; This program is free software; you can redistribute it and/or
  5. ; modify it under the terms of the GNU General Public License
  6. ; as published by the Free Software Foundation; either version 2
  7. ; of the License, or (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. ;
  18. ; Author: David J Benn
  19. ;   Date: 19th March 1994
  20. ;
  21. ; registers d0-d6 and a0-a3 are modified by some of the following. BEWARE!
  22. ;
  23. ; a4,a5 are used by link/unlk.
  24. ; a6 is library base holder.
  25. ; a7 is stack pointer. 
  26. ; d7 is used for array index calculations.
  27. ;
  28.  
  29.        ; simple string functions
  30.        xdef      _strcpy
  31.        xdef      _strcat
  32.        xdef      _strlen
  33.     xdef    _strcmp
  34.        xdef      _streq
  35.        xdef      _strne
  36.        xdef      _strgt
  37.        xdef      _strlt
  38.        xdef      _strge
  39.        xdef      _strle
  40.        xdef      _asc
  41.        xdef      _chrstring
  42.  
  43.     SECTION string_code,CODE
  44.  
  45. ;*** SIMPLE STRING FUNCTIONS ***
  46.  
  47. ;
  48. ; copy a source string (a1) to destination string (a0)
  49. ;
  50. _strcpy:
  51.         cmp.b     #0,(a1)
  52.         beq.s   _quitstrcpy  ; source EOS?
  53.         move.b    (a1)+,(a0)+  ; copy from source to dest
  54.         bra.s     _strcpy  
  55. _quitstrcpy: 
  56.         move.b (a1),(a0)    ; copy the EOS marker!
  57.         rts
  58.  
  59. ;
  60. ; concatenate two strings (source = a1, dest = a0)
  61. ;
  62. _strcat:
  63. _findeos:
  64.         cmp.b     #0,(a0)+     ; found dest EOS?
  65.         bne.s   _findeos
  66.         subq      #1,a0        ; backup to EOS
  67. _concat:
  68.         cmp.b     #0,(a1)
  69.         beq.s   _quitstrcat  ; source EOS?
  70.         move.b    (a1)+,(a0)+  ; copy from source to dest
  71.         bra.s   _concat
  72. _quitstrcat: 
  73.         move.b (a1),(a0)    ; copy the EOS marker!
  74.         rts
  75.  
  76. ;
  77. ; find the length of the string pointed to by a2. d0=length (LONG).
  78. ;
  79. _strlen:
  80.     moveq    #0,d0
  81. _strlenloop:
  82.     cmpi.b    #0,(a2)+    
  83.     beq.s    _strlenexit
  84.     addq    #1,d0
  85.     bra.s    _strlenloop
  86. _strlenexit:
  87.     rts
  88.     
  89. ;
  90. ; - lexicographical comparison of two strings. a0=str1; a1=str2.
  91. ; - returns a value in d0 of (a0)-(a1) where (a0)<>(a1) or 0 if EOS reached.
  92. ;   (See "Amiga C for Beginners", pp 154,155, Abacus books)
  93. ;
  94. _strcmp:
  95.     move.b    (a0),d0
  96.     move.b    (a1),d1
  97.     cmp.b    d0,d1
  98.     bne.s    _strcmpne    ; (a0)<>(a1)
  99.  
  100.     cmpi.b    #0,(a0)        ; EOS?
  101.     beq.s    _strcmpeq
  102.     
  103.     addq    #1,a0        ; a0++
  104.     addq    #1,a1        ; a1++
  105.     
  106.     bra.s    _strcmp
  107.  
  108. _strcmpeq:
  109.     move.b    #0,d0        ; (a0)=(a1)
  110.     rts    
  111.     
  112. _strcmpne:
  113.     move.b    (a0),d0
  114.     sub.b    (a1),d0        ; d0=(a0)-(a1)
  115.     rts
  116.  
  117. ;
  118. ; test for string equivalence [str1 = str2]. a0=str1; a1=str2.
  119. ;
  120. _streq:
  121.     jsr    _strcmp
  122.     cmp.b    #0,d0
  123.     beq.s    _streqT
  124.  
  125.     moveq    #0,d0        ; str1<>str2
  126.     rts
  127.  
  128. _streqT:
  129.     moveq    #-1,d0        ; str1=str2
  130.     rts
  131.         
  132. ;
  133. ; tests for string inequality. a0=str1; a1=str2.
  134. ; d0 contains boolean result.
  135. ;
  136. _strne:
  137.     jsr    _strcmp
  138.     cmp.b    #0,d0
  139.     bne.s    _strneT
  140.  
  141.     moveq    #0,d0        ; str1=str2
  142.     rts
  143.  
  144. _strneT:
  145.     moveq    #-1,d0        ; str1<>str2
  146.     rts
  147.  
  148. ;
  149. ; tests for str1 > str2. a0=str1; a1=str2.
  150. ; d0 contains boolean result.
  151. ;
  152. _strgt:
  153.     jsr    _strcmp
  154.     cmp.b    #0,d0
  155.     bgt.s    _strgtT
  156.  
  157.     moveq    #0,d0        ; str1<=str2
  158.     rts
  159.  
  160. _strgtT:
  161.     moveq    #-1,d0        ; str1>str2
  162.     rts
  163.     
  164. ;
  165. ; tests for str1 < str2. a0=str1; a1=str2.
  166. ; d0 contains boolean result.
  167. ;
  168. _strlt:
  169.     jsr    _strcmp
  170.     cmp.b    #0,d0
  171.     blt.s    _strltT
  172.  
  173.     moveq    #0,d0        ; str1>=str2
  174.     rts
  175.  
  176. _strltT:
  177.     moveq    #-1,d0        ; str1<str2
  178.     rts
  179.  
  180. ;
  181. ; tests for str1 >= str2. a0=str1; a1=str2.
  182. ; d0 contains boolean result.
  183. ;
  184. _strge:
  185.     jsr    _strcmp
  186.     cmp.b    #0,d0
  187.     bge.s    _strgeT
  188.  
  189.     moveq    #0,d0        ; str1<str2
  190.     rts
  191.  
  192. _strgeT:
  193.     moveq    #-1,d0        ; str1>=str2
  194.     rts
  195.  
  196. ;
  197. ; tests for str1 <= str2. a0=str1; a1=str2.
  198. ; d0 contains boolean result.
  199. ;
  200. _strle:
  201.     jsr    _strcmp
  202.     cmp.b    #0,d0
  203.     ble.s    _strleT
  204.  
  205.     moveq    #0,d0        ; str1>str2
  206.     rts
  207.  
  208. _strleT:
  209.     moveq    #-1,d0        ; str1<=str2
  210.     rts
  211.  
  212. ;
  213. ; CHR$ function. Assumes ASCII value in d0 and target string address in a0.
  214. ;
  215. _chrstring:
  216.        move.b d0,(a0)+
  217.        move.b #0,(a0)
  218.        rts
  219.  
  220. ;
  221. ; returns the ASCII value (in d0) of the first character pointed to by a2.
  222. ; (returns SHORT) 
  223. ;
  224. _asc:
  225.     move.b    (a2),d0
  226.     ext.w    d0
  227.        cmpi.w    #0,d0
  228.     bge.s    _exit_asc
  229.     add.w    #256,d0        ; make positive if necessary
  230. _exit_asc:        
  231.     rts
  232.  
  233.     END
  234.